from odoo import http
import akshare  as ak
from odoo.http import request

class EpidemicTongjiPage(http.Controller):
    @http.route('/data/map',type='json',auth='user')
    def data_tongji(self,**kwargs):
        return self._data_news()

    def _data_news(self):
        """获取新闻"""
        news = ak.covid_19_163(indicator="实时资讯新闻播报")
        inxs = news.index
        a_target = """<a href="{}">{}</a> <br/>"""
        news_target = ''
        for inx in inxs:
            col = news.loc[inx]
            current_a = a_target.format(col[-1], col[0])
            news_target += current_a
            if inx >= 10: break
        news_target = """<div>{}</div>""".format(news_target)
        return news_target
